import java.util.Arrays;
import java.util.Random;

public class Test {
    //生成一个有序的数组
    public static  void orderArray(int[]array){
        for(int i=0;i<array.length;i++){
            array[i]=i;
            //逆序
            array[i]=array.length-i;
        }
    }
    //生成一个无需的数组
    public static void notOrderarray(int[]array){
        Random random=new Random();
        for(int i=0;i<array.length;i++){
            array[i]=random.nextInt(100000);
        }

    }
    //测试简单的数据能否执行，测试算法是否正确
    public static void  testSimple(){
        int[]array={9,1,2,5,7,4,8,6,3,5};
        System.out.println("排序前："+Arrays.toString(array));
//        Sort.insertSort(array);
       // Sort.selectSort2(array);
        //Sort.heapSort(array);
        //Sort.bubbleSort(array);
        Sort.mergeSort(array);
        System.out.println("排序后："+Arrays.toString(array));
    }
    public static void testOther(){
        int[]array=new int[10_0000];
        orderArray(array);
        notOrderarray(array);
        testInsert(array);
        testshellsort(array);
        testSelectSort(array);
        testheapSort(array);
        testbubbleSort(array);
        testquickSort(array);
    }
    public static void testInsert(int[]array){
        array=Arrays.copyOf(array,array.length);
        long startTime=System.currentTimeMillis();
        Sort.insertSort(array);
        long endTime=System.currentTimeMillis();
        System.out.println("直接插入排序耗时："+(endTime-startTime));
    }
    public static void  testshellsort(int[]array){
        array=Arrays.copyOf(array,array.length);
        long startTime=System.currentTimeMillis();
        Sort.shellSort(array);
        long endTime=System.currentTimeMillis();
        System.out.println("希尔排序耗时："+(endTime-startTime));
    }
    public  static void testSelectSort(int[]array){
        array=Arrays.copyOf(array,array.length);
        long startTime=System.currentTimeMillis();
        Sort.selectSort2(array);
        long endTime=System.currentTimeMillis();
        System.out.println("直接选择排序耗时："+(endTime-startTime));
    }
    public  static void testheapSort (int[]array){
        array=Arrays.copyOf(array,array.length);
        long startTime=System.currentTimeMillis();
        Sort.heapSort(array);
        long endTime=System.currentTimeMillis();
        System.out.println("堆排序耗时："+(endTime-startTime));
    }
    public  static void testbubbleSort(int[]array){
        array=Arrays.copyOf(array,array.length);
        long startTime=System.currentTimeMillis();
        Sort.bubbleSort(array);
        long endTime=System.currentTimeMillis();
        System.out.println("冒泡排序耗时："+(endTime-startTime));
    }
    public  static void testquickSort(int[]array){
        array=Arrays.copyOf(array,array.length);
        long startTime=System.currentTimeMillis();
        Sort.quickSort(array);
        long endTime=System.currentTimeMillis();
        System.out.println("快速排序耗时："+(endTime-startTime));
    }

    public static void main(String[] args) {
        testSimple();
       // testOther();
    }
}
